package com.vlong.town.service.activity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.activity.ActivityInfo;
import com.vlong.town.mapper.activity.ActivityInfoMapper;

/**
 * 文化活动信息业务实现类
 * @author Assassin
 */
@Service
public class ActivityInfoService {

    // Fields

    @Autowired
    private ActivityInfoMapper activityInfoMapper;// 文化活动信息Mapper接口

    // Methods

    /**
     * 添加文化活动信息
     * @param townId 村镇Id
     * @param title 文化活动标题
     * @param content 文化活动内容
     * @param desc 文化活动简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void add(Long townId, String title, String content, String desc, String thumbnail) {
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.setTownId(townId);
        activityInfo.setState(1);
        activityInfo.setStatus(1);
        activityInfo.setTitle(title);
        activityInfo.setContent(content);
        activityInfo.setDesc(desc);
        activityInfo.setThumbnail(thumbnail);
        Long cuTime = System.currentTimeMillis();
        activityInfo.setCreateTime(cuTime);
        activityInfo.setUpdateTime(cuTime);
        activityInfo.setTranslate(1);
        this.activityInfoMapper.insert(activityInfo);
    }

    /**
     * 逻辑删除文化活动信息
     * @param noticeId 主键值
     */
    @Transactional
    public void delete(Long noticeId) {
        this.activityInfoMapper.delete(noticeId);
    }

    /**
     * 修改文化活动信息
     * @param noticeId 文化活动Id
     * @param title 文化活动标题
     * @param content 文化活动内容
     * @param desc 文化活动简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void update(Long noticeId, String title, String content, String desc, String thumbnail,Integer translate) {
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.setActivityId(noticeId);
        activityInfo.setTitle(title);
        activityInfo.setContent(content);
        activityInfo.setDesc(desc);
        activityInfo.setThumbnail(thumbnail);
        activityInfo.setTranslate(translate);
        activityInfo.setUpdateTime(System.currentTimeMillis());
        this.activityInfoMapper.update(activityInfo);
    }

    /**
     * 主键查询文化活动信息
     * @param noticeId 文化活动Id
     * @return
     */
    @Transactional(readOnly = true)
    public ActivityInfo queryById(Long noticeId) {
        return this.activityInfoMapper.selectById(noticeId);
    }

    /**
     * 查询文化活动信息
     * @param title 文化活动标题
     * @param content 文化活动内容
     * @param desc 文化活动简介
     * @return List<ActivityInfo>
     */
    @Transactional(readOnly = true)
    public List<ActivityInfo> queryList(String title, String content, String desc,Integer translate) {
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.setTitle(title);
        activityInfo.setContent(content);
        activityInfo.setDesc(desc);
        activityInfo.setTranslate(translate);
        return this.activityInfoMapper.selectList(activityInfo);
    }

}
